#ifndef _K_RUNTIME_
#define _K_RUNTIME_

#ifndef __linux

#if _MSC_VER > 1000
#pragma once
#endif 

#ifndef _WIN32_WINNT
#define _WIN32_WINNT  0x0400
#endif

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#else

#define IN
#define OUT

typedef int INT;
typedef int *PINT;
typedef int *LPINT;

typedef long LONG;
typedef long *PLONG;
typedef long *LPLONG;

typedef unsigned long ULONG;
typedef unsigned long *PULONG;
typedef unsigned long *LPULONG;

typedef char INT8;
typedef char *PINT8;
typedef char *LPINT8;

typedef unsigned char UINT8;
typedef unsigned char *PUINT8;
typedef unsigned char *LPUINT8;

typedef unsigned char UCHAR;
typedef unsigned char *PUCHAR;
typedef unsigned char *LPUCHAR;

typedef unsigned char BYTE;
typedef unsigned char *PBYTE;
typedef unsigned char *LPBYTE;

typedef short INT16;
typedef short *PINT16;
typedef short *LPINT16;

typedef unsigned short UINT16;
typedef unsigned short *PUINT16;
typedef unsigned short *LPUINT16;

typedef unsigned short WORD;
typedef unsigned short *PWORD;
typedef unsigned short *LPWORD;

typedef int INT32;  
typedef int *PINT32;  
typedef int *LPINT32;  

typedef unsigned int UINT32;
typedef unsigned int *PUINT32;
typedef unsigned int *LPUINT32;

typedef long long INT64; 
typedef long long *PINT64; 
typedef long long *LPINT64; 

typedef unsigned long long UINT64;
typedef unsigned long long *PUINT64;
typedef unsigned long long *LPUINT64;

typedef unsigned long DWORD; 
typedef DWORD *PDWORD;
typedef DWORD *LPDWORD;

typedef unsigned long HWND; 
typedef unsigned long HANDLE; 

typedef void *PVOID; 
typedef void *LPVOID; 
typedef void *PCVOID; 
typedef void *LPCVOID; 

typedef char *PSTR; 
typedef char *LPSTR; 

typedef const char *PCSTR; 
typedef const char *LPCSTR; 

typedef char *PWSTR; 
typedef char *LPWSTR; 

typedef const char *PCWSTR; 
typedef const char *LPCWSTR; 

#ifdef _UNICODE
typedef wchar_t *PTSTR; 
typedef wchar_t *LPTSTR; 
typedef const wchar_t *PCTSTR; 
typedef const wchar_t *LPCTSTR; 
#else
typedef char *PTSTR; 
typedef char *LPTSTR; 
typedef const char *PCTSTR; 
typedef const char *LPCTSTR; 
#endif

typedef int BOOL;
#define TRUE 1
#define FALSE 0

typedef struct tagRECT
{
	LONG    left;
	LONG    top;
	LONG    right;
	LONG    bottom;
} RECT, *LPRECT;

typedef struct tagPOINT
{
	LONG  x;
	LONG  y;
} POINT, *PPOINT;

typedef struct _GUID {          // size is 16
	DWORD Data1;
	WORD   Data2;
	WORD   Data3;
	BYTE  Data4[8];
} GUID;

#define MAX_PATH 260
#define CALLBACK

#define ZeroMemory(x, y) memset(x, 0, y)
#define max(a,b)            (((a) > (b)) ? (a) : (b))
#define min(a,b)            (((a) < (b)) ? (a) : (b))

#define FILE_CURRENT	1
#define FILE_END		2
#define FILE_BEGIN		0

#define MAKEWORD(a, b)      ((WORD)(((BYTE)(a)) | ((WORD)((BYTE)(b))) << 8))
#define MAKELONG(a, b)      ((LONG)(((WORD)(a)) | ((DWORD)((WORD)(b))) << 16))
#define LOWORD(l)           ((WORD)(l))
#define HIWORD(l)           ((WORD)(((DWORD)(l) >> 16) & 0xFFFF))
#define LOBYTE(w)           ((BYTE)(w))
#define HIBYTE(w)           ((BYTE)(((WORD)(w) >> 8) & 0xFF))

#define SUCCEEDED(x)		((x) > 0)

#include <unistd.h>
#include <pthread.h>

#define __stdcall

#define SOCKET_ERROR -1

#endif	//__linux

#include <tchar.h>
#include <stdarg.h> 
#include <direct.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#ifndef ITOA
#define ITOA(NUMBER)  #NUMBER
#endif

#ifndef __TEXT_LINE__
#define __TEXT_LINE__(LINE) ITOA(LINE)
#endif

#ifndef KSG_ATTENTION
#define KSG_ATTENTION(MSG) __FILE__"("__TEXT_LINE__(__LINE__)") : ATTENTION"#MSG
#endif

#ifdef KRUNTIME_EXPORTS_DLL
#undef KRUNTIME_API
#undef KRUNTIME_CLASS
#define KRUNTIME_API __declspec(dllexport)
#define KRUNTIME_CLASS __declspec(dllexport)
#endif

#ifdef KRUNTIME_EXPORTS_LIB
#undef KRUNTIME_API
#undef KRUNTIME_CLASS 
#define KRUNTIME_API extern
#define KRUNTIME_CLASS 
#endif

#ifdef KRUNTIME_IMPORTS_DLL
#undef KRUNTIME_API
#undef KRUNTIME_CLASS
#define KRUNTIME_API __declspec(dllimport)
#define KRUNTIME_CLASS __declspec(dllimport)
#endif

#ifdef KRUNTIME_IMPORTS_LIB
#undef KRUNTIME_API
#undef KRUNTIME_CLASS
#define KRUNTIME_API extern
#define KRUNTIME_CLASS 
#endif

#ifndef KRUNTIME_API
#define KRUNTIME_API extern
#endif

#ifndef KRUNTIME_CLASS
#define KRUNTIME_CLASS 
#endif

#ifdef _WINDOWS
#define PATH_DELIMITER '\\'
#else
#define PATH_DELIMITER '/'
#endif

#define IS_PATH_DELIMITER(x) ('\\' == (x) || '/' == (x))

#ifndef ARRAY_LENGTH
#define ARRAY_LENGTH(x) (sizeof(x)/sizeof(x[0]))
#endif

//---------------------------------------------------------------------------
#endif	//_K_RUNTIME_
